<?php 
require_once  __DIR__ . '/includes/authenticate.php';

?>

<br>

<div id="container-fluid">
<div id="row">
<div id="col-md-12">
<form method="post" action="" class="hidden-print">

    <div class="form-group">
	  <div class="col-md-offset-3 col-md-6">        
          <select class="form-control" name="playerID">
         	<option value="" disabled="disabled" selected="selected">Select a player to view profile of</option>

<?php

if (isset($_POST['season'])) {
  
  $season = $_POST['season'];

  include_once './db_bb_connect.php'; 

  $sql = "SELECT users.firstname, users.lastname, users.user_key, teams.season, teams.playerID
  FROM users
  JOIN teams
  ON users.user_key = teams.playerID
  WHERE teams.season = '$season'
  ORDER BY users.firstname";

  $result=$db->query($sql);

  while($row=$result->fetch_assoc()){	

    $user_key=$row['user_key']; 
    $firstname=$row['firstname']; 
    $lastname=$row['lastname']; 
  
  echo "<option value=\"$user_key\">$firstname $lastname</option>";

};

}
  ?>

          </select>


		</div>
    </div>

    <input type="hidden" name="season" value="<?= $season; ?>">

</form>

  </div>
  </div>
</div>
<br>


<div id="row">
<div id="col-md-12">  
  <div id="fullplayerprofile"></div>
</div>
</div>



<script type="text/javascript">
  
$("select").on( "change", function( e ) {
  postData = $(this.form).serialize();
  $.ajax({
    type: "POST",
    url: "./playerprofile_loader.php",
    data: postData,
    success: function(data) {
      $("#fullplayerprofile").html(data);
    }
  }); 
  e.preventDefault();
});


</script>